package com.datastructure.test.maxmutilofthree;

import java.util.Arrays;

public class MaxMultiplyOfThree {


    public static void main(String[] args) {
        MaxMultiplyOfThree maxMultiplyOfThree = new MaxMultiplyOfThree();
        int[] data = {-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000,-10000};
        long solve = maxMultiplyOfThree.solve(data);
        System.out.println(solve);
    }

    public long solve (int[] A) {
        // write code here
        int length = A.length;
        Arrays.sort(A);
        long max = Math.max((long)A[0]*A[1]*A[2],(long)A[length-1]*A[length-2]*A[length-3]);
        max = Math.max(max, (long) A[length - 1] *A[0]*A[1]);
        return Math.max(max, (long) A[length - 1] *A[0]*A[1]);
    }
}
